package com.big.tree.service.observer;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.ApplicationEventPublisherAware;
import org.springframework.stereotype.Service;

@Slf4j
@Service
public class UserArrearsPublisher implements ApplicationEventPublisherAware {

    private ApplicationEventPublisher applicationEventPublisher;

    @Override
    public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) {
        this.applicationEventPublisher = applicationEventPublisher;
    }

    public void arrears(String username) {
        // 执行欠费逻辑
        log.info("被观察者 用户欠费,用户名称", username);
        // 发布
        applicationEventPublisher.publishEvent(new UserArrearsEvent(this, username));
    }
}
